/**
* @Title: selfFeedback_detail_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年11月14日 下午10:20:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('SelfFeedbackDetailCtrl', ['$scope','$state','$stateParams','CaseCommonService','$http','BaseURL','Modal','SelfFeedbackService','$modal',
	                                function($scope,$state,$stateParams,CaseCommonService,$http,baseUrl,Modal,SelfFeedbackService,$modal){
		$scope.selfFeedbackService = SelfFeedbackService;
		var warnNo=$stateParams.warnNo;
		$scope.columns = [
		                  {
			                   label: '省科室',
							   map: 'deptName',
							   width: '15%'
						  }, {
							   label: '费用类型',
							   map : 'warnfeeType',
							   width : '20%'
						  }, {
							   label: '费用金额(元)',
							   map: 'feeAmount',
							   width: '21%'							   
						  }, {
							   label: '医院科室',
							   map: 'orgDepName',
							   width: '17%'							   
						  }, {
							   label: '概要',
							   map: 'warnReason',
							   width: '27%'
						  }
						 ];
		var params = {
						orgId:"2",
						warnNo:warnNo
					 };
		
		$scope.tableData = [];
		$scope.feeAmountCount = "0.00";
		
		//获取通知单信息
		SelfFeedbackService.getSelfFeedbackDetail(params).success(function(res){
			$scope.selfFeedback={};
			//$scope.selfFeedback.requisitionNo=warnNo;
			//$scope.selfFeedback.areaName="厦门市";
			angular.forEach(res.notice,function(data,index){				
				if (data.docKey =="name") {
					$scope.selfFeedback.orgName=data.docValue1;
				}
				if (data.docKey =="content") {
					$scope.selfFeedback.reason=data.docValue1;
				}
				if (data.docKey =="dateend") {
					$scope.selfFeedback.endWarningDate=data.docValue1;
				}
				if (data.docKey =="datestart") {
					$scope.selfFeedback.startWarningDate=data.docValue1;
				}
				if (data.docKey =="requirement") {
					$scope.selfFeedback.demand=data.docValue1;
				}
				if (data.docKey =="regionName") {
					$scope.selfFeedback.areaName=data.docValue1;
				}
				if (data.docKey =="noticeNo") {
					$scope.selfFeedback.noticeNo=data.docValue1;
				}
			});	
			$scope.selfFeedback.WarningDate=SelfFeedbackService.setPriodDate($scope.selfFeedback.startWarningDate,$scope.selfFeedback.endWarningDate);
			$scope.selfFeedback.requisitionNo=res.feedback.warnNoBiz;
			$scope.selfFeedback.check=res.feedback.checkSituation;//自查情况
			$scope.selfFeedback.corrective=res.feedback.checkMeasure;//整改措施
			//$scope.selfFeedback.corrective=res.feedback.checkSumamount;	//合计金额		
			$scope.tableData = res.feedbackDetail;
			calAmount();
		});
		
		//计算合计金额
		function calAmount() {
			var countNum = 0;
			angular.forEach($scope.tableData,function(data,index){
				countNum = countNum + parseFloat(data.feeAmount) * 100;
			});
			$scope.feeAmountCount = (countNum/100).toFixed(2);
		}
		
		//返回列表页面
		$scope.backSelfFeedback = function(){
        	$state.go("selfFeedback.selfFeedbackList");
        }
		
		//--------------------------------------------------------
		/**
		 * 显示附件
		 */
		$scope.path="";
		var params2 = {id:warnNo};
		CaseCommonService.showImage(params2).success(function(res){
			$scope.fileData = res.result.imgList;
		    $scope.path=res.path;
		});
	    
		//显示下载和查看按钮
		$scope.showId = "";
        $scope.mouseover=function(id)
        {
        	 $scope.showId = id;
        }
        
        /**
         * 下载文件
         */
        $scope.downLoadFile=function(item){
            var path="";
            var suffix = item.name.substring(0,item.name.lastIndexOf('.'));
            window.location = baseUrl + 'agreement/downloadFile.do?fileInfoId='+item.businessNo+'/insurance/'+suffix+
                '&fileName='+item.name+'&path='+path;
        }
        /**
         * 查看文件
         */
        $scope.openLoadFile=function(item){
            var path= $scope.path+'/'+item.businessNo+'/insurance/'+ item.name;
           var  param={filePath:path};
            $http.post(baseUrl + 'agreement/exitFile.do',param).success(function(data) {
                if(data.state!="error")
                {
                    window.open(baseUrl + '/file/openPdfFile.do?filePath='+path);
                }else
                {
                    Modal.alert(data.msg);
                }
            })
        }
	     //--------------------------------------------------------
		
		//通知单下载
		$scope.downFile=function(){
			var scope = $scope.$new();
			var modalInstance = $modal.open({
	      	      templateUrl: baseUrl +'views/hcpms/warning/warnView/warningViewNotice_view.html',
	      	      backdrop:'static',
				  size:'sm',
				  scope:scope,
	      	      controller:function($modalInstance,$scope){
	      	    	 
	      	    		 
	      	    	 $scope.$watch('$viewContentLoaded',function(){
	      	    			openFile('03','warningViewNoticeOpenpdf');
	      	        });
	      	    	  $scope.onOk = function(){
				  		   $modalInstance.dismiss();
				  	   }	
				  }
	  	    });
			
		}
		
		/**打开PDF文件*/
		   function openFile(param,openpdfId){
		   			var success = new PDFObject({ url:baseUrl+'HcpmsWarnDownFile/downPdfFile.do?warnNo='+warnNo+'&docType='+param,
		   				pdfOpenParams: { navpanes: 1,
		                 toolbar: 1,
		                 statusbar: 1,
		                 view: 'FitV',
		                 pagemode: 'thumbs'
		   			}}).embed(openpdfId);
		   }
		
	}]);
})();